1
//--------------------------------------------------------------------------
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // File: CurrentThreadTaskScheduler.cs
7 //--------------------------------------------------------------------------
9 using System
.Collections
.Generic
;
12 namespace System
.Threading
.Tasks
.Schedulers
14 /// <summary>Provides a task scheduler that runs tasks on the current thread.</summary>
15 public sealed class CurrentThreadTaskScheduler
: TaskScheduler
17 /// <summary>Runs the provided Task synchronously on the current thread.</summary>
18 /// <param name="task">The task to be executed.</param>
19 protected override void QueueTask(Task task
)
24 /// <summary>Runs the provided Task synchronously on the current thread.</summary>
25 /// <param name="task">The task to be executed.</param>
26 /// <param name="taskWasPreviouslyQueued">Whether the Task was previously queued to the scheduler.</param>
27 /// <returns>True if the Task was successfully executed; otherwise, false.</returns>
28 protected override bool TryExecuteTaskInline(Task task
, bool taskWasPreviouslyQueued
)
30 return TryExecuteTask(task
);
33 /// <summary>Gets the Tasks currently scheduled to this scheduler.</summary>
34 /// <returns>An empty enumerable, as Tasks are never queued, only executed.</returns>
35 protected override IEnumerable
<Task
> GetScheduledTasks()
37 return Enumerable
.Empty
<Task
>();
40 /// <summary>Gets the maximum degree of parallelism for this scheduler.</summary>
41 public override int MaximumConcurrencyLevel { get { return 1; }
}